package com.lightsh.common;

import java.util.ArrayList;
import java.util.Arrays;

import com.lightsh.utility.Utility;

import android.graphics.Path;

public class PaintStroke {
	private final float[] mStrokePoints;
	private final int mColor;
	private final int mType;
	private final int mWidth;
	public static PaintStroke newInstance(ArrayList<Float> stroke, int color, int type, int width){
		float[] strokePoints = new float[stroke.size()];
		for(int i = 0; i < strokePoints.length; ++i){
			strokePoints[i] = stroke.get(i).floatValue();
		}
		return new PaintStroke(strokePoints, color, type, width);
	}
	public static PaintStroke newInstance(float[] strokePoints, int color, int type, int width){
		return new PaintStroke(strokePoints, color, type, width);
	}
	private PaintStroke(float[] strokePoints, int color, int type, int width){
		if(strokePoints == null || strokePoints.length <= 0 || strokePoints.length % 2 != 0){
			throw new IllegalArgumentException("strokePoints length must >= 2 && %2 == 0!");
		}
		mStrokePoints = strokePoints;
		mColor = color;
		mType = type;
		mWidth = width;
	}
	
	public Path toPath(Path inPath){
		inPath.reset();
		inPath.moveTo(mStrokePoints[0], mStrokePoints[1]);
		float lastX = mStrokePoints[0];
		float lastY = mStrokePoints[1];
		int i = 2;
		for(; i < mStrokePoints.length; i+=2){
			Utility.pathQuadTo(inPath, lastX, lastY, mStrokePoints[i], mStrokePoints[i + 1]);
			lastX = mStrokePoints[i];
			lastY = mStrokePoints[i + 1];
		}
		inPath.lineTo(lastX, lastY);
		return inPath;
	}
	public float[] getStrokePoints(){
		return mStrokePoints;
	}
	public int getColor(){
		return mColor;
	}
	public int getType(){
		return mType;
	}
	public int getWidth(){
		return mWidth;
	}
}
